using System;

namespace RobotWebApiService.Models
{
    public class ApiResponse<T>
    {
        public bool Success { get; set; }
        public string Message { get; set; }
        /// <summary>
        /// 返回数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 通用成功数据返回
        /// </summary>
        /// <param name="success"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        public ApiResponse(bool success, string message, T data)
        {
            Success = success;
            Message = message;
            Data = data;
        }
        /// <summary>
        /// 通用无实体数据返回
        /// </summary>
        /// <param name="success"></param>
        /// <param name="message"></param>
        public ApiResponse(bool success, string message)
        {
            Success = success;
            Message = message;
            Data = default(T);
        }

    }

    /// <summary>
    /// 分页响应模型
    /// </summary>
    public class PagedApiResponse<T> : ApiResponse<T>
    {
        public int PageNumber { get; set; }
        public int PageSize { get; set; }
        public int TotalCount { get; set; }
        public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);

        public PagedApiResponse(bool success, string message, T data, 
            int pageNumber, int pageSize, int totalCount) 
            : base(success, message, data)
        {
            PageNumber = pageNumber;
            PageSize = pageSize;
            TotalCount = totalCount;
        }
    }
}